<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <input v-model="val" type="text">
        <div>
            <ul>
                <li v-for="item in list">
                    {{ item.name }}
                </li>
            </ul>

            <p v-show="list.length === 0">
                暂无数据
            </p>
        </div>

        <p>
            条件一 <input type="text">
        </p>
        <p>
            条件二 <input type="text">
        </p>
    </div>

    <script src="./vue.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/1.0.0-alpha.1/axios.js"></script>
    <!-- mockjs -->
    <script src="https://cdn.bootcdn.net/ajax/libs/Mock.js/1.0.1-beta3/mock-min.js"></script>
    <script>
        let arr = [
            {
                name: "zhangsan"
            },
            {
                name: "zhangli"
            },
            {
                name: "lisan"
            },
            {
                name: "lisi"
            }
        ]

        Mock.mock(RegExp("/api/search" + "*."), (req) => {
            let name = req.url.split('=')[1]
            let filterArr = arr.filter(item => item.name.includes(name))
            console.log(filterArr)
            return filterArr
        })

        new Vue({
            el: "#app",
            data: {
                val: "",
                list: []
            },
            watch: {
                val(name) {
                    if (name.length === 0) {
                        this.list = []
                    } else {
                        axios.get("/api/search", {
                            params: {
                                name
                            }
                        }).then(res => {
                            this.list = res.data
                        })
                    }

                }
            }
        })
    </script>
</body>

</html>